<%-- 
    Document   : doreg
    Created on : 2019-9-4, 9:14:05
    Author     : danny
--%>

<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
// 获取用户输入
String userName = request.getParameter("userName");
String pwd = request.getParameter("password");
log(userName + "\t" + pwd);

// 插入数据库
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "danpleny";
String dbpwd = "123456";

int r = 0;

try (Connection con = DriverManager.getConnection(url, user, dbpwd)) {
    // 插入数据
    PreparedStatement pst = con.prepareStatement("insert into EASYBUY_USER(EU_USER_ID,EU_USER_NAME,EU_PASSWORD,EU_SEX,EU_STATUS) VALUES(?,'测试',?,'M',1)");
    pst.setString(1, userName);
    pst.setString(2, pwd);
    r = pst.executeUpdate();
} catch (Exception e) {
    e.printStackTrace();
}

// 根据结果进行页面转向
if (r == 1) {
    request.getRequestDispatcher("regSuccess.jsp").forward(request, response);
//    response.sendRedirect("regSuccess.jsp");
} else {
    request.getRequestDispatcher("regFail.jsp").forward(request, response);
}
%>
